﻿Imports System.Data.OleDb
Public Module cmd
    Public Function GetConnection() As OleDbConnection
        Dim cn As New OleDbConnection("Provider=Microsoft.Ace.Oledb.12.0; Data Source=|DataDirectory|\Database1.accdb;")
        cn.Open()
        Return cn
    End Function
    Public Sub ExecuteNonquery(ByVal sql As String)
        Dim cmd As New OleDbCommand(sql, GetConnection)
        cmd.ExecuteNonQuery()
    End Sub
    Public Function ExcecuteScalar(ByVal sql As String) As Object
        Dim cmd As New OleDbCommand(sql, GetConnection)
        Dim val = cmd.ExecuteScalar
        Return val
    End Function
    Public Function ExcecuteDatatable(ByVal sql As String) As DataTable
        Dim cmd As New OleDbCommand(sql, GetConnection)
        Dim dr As OleDbDataReader = cmd.ExecuteReader
        Dim dt As New DataTable
        dt.Load(dr)
        dr.Close()
        Return dt
    End Function
End Module
